package cn.xyy.system.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.xyy.common.domain.system.auth.Permission;
import cn.xyy.common.utils.StringUtils;
import cn.xyy.jdbc.BaseDaoImpl;

/**
 * 权限数据持久层
 * 
 * @author xyy
 *
 */
@Repository
public class PermissionDao extends BaseDaoImpl {

	public List<Permission> selectAll() {
		String sql = "SELECT perm_id as id,title, parent_id as parentId,types,i_frame as iframe,path,levels ,description,sorts,name,component,icon,cache,hide,hide_children as hideChildren,permission_code as permissionCode,redirect,status from t_sys_permission order by sorts asc";
		return super.select(sql, Permission.class);
	}

	public List<Permission> selectByRole(Integer[] roleIdList) {
		String sql = "SELECT p.perm_id as id, p.parent_id as parentId,title,types,i_frame as iframe,path,levels ,p.description,p.sorts,p.name,component,icon,cache,hide,hide_children as hideChildren,permission_code as permissionCode,redirect,status  from t_sys_role_permission rr inner join t_sys_permission p on rr.perm_id=p.perm_id where rr.role_id in ("
				+ StringUtils.join(roleIdList, ",") + ") and status=1 order by p.sorts asc";
		return super.select(sql, Permission.class);
	}

	public int insert(Permission permission) {
		return super.insert(permission);
	}

	public int update(Permission permission) {
		return super.update(permission);
	}

	public int delete(Permission permission) {
		return super.delete(permission);
	}

	public List<Permission> select(Permission permission) {
		return super.select(permission);
	}

	public Permission select(Integer id) {
		return super.selectById(id, Permission.class);
	}
}
